package xiangmu.schoolpaper.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xiangmu.schoolpaper.exception.ContentNullException;
import xiangmu.schoolpaper.mapper.StudentDataListMapper;
import xiangmu.schoolpaper.pojo.DTO.StudentDetailScoreDTO;
import xiangmu.schoolpaper.pojo.VO.StudentDetailScoreVO;
import xiangmu.schoolpaper.pojo.VO.StudentOneScoreVO;
import xiangmu.schoolpaper.service.StudentDataListService;

import java.util.List;

@Service
public class StudentDataListServiceImpl implements StudentDataListService {
    @Autowired
    private StudentDataListMapper studentDataListMapper;

    @Override
    public String download(Integer paperId) {
        return studentDataListMapper.download(paperId);
    }

    @Override
    public List<StudentOneScoreVO> getOneScore(Integer studentId) {
        return studentDataListMapper.getOneScore(studentId);
    }

    @Override
    public List<StudentDetailScoreVO> getDetailScore(StudentDetailScoreDTO s) {
        List<StudentDetailScoreVO> studentDetailScoreVO= studentDataListMapper.getDetailScore(s);
        //判断该返回的Score是否为null，如果为空则返回错误：暂无数据
        if(studentDetailScoreVO.isEmpty()){
            throw new ContentNullException("数据为空，请检查该论文是否上传");
        }
        //判断该返回的Score是否为100,如果为100则不返回建议，只返回依据
        studentDetailScoreVO.forEach(e->{
            if(e.getScore()==100){
                e.setSuggest(null);
            }
        });
        //如果正常则直接放回相关的数据
        return studentDetailScoreVO;
    }
}
